home *** CD-ROM | disk | FTP | other *** search
/ Cracking 2 / Cracking II..iso / Texty / crackme / CRUEME.ASM < prev    next >
Encoding:
Assembly Source File  |  1999-02-13  |  13.5 KB  |  516 lines

  1. ;-----------------------------------------------------------------------------------
  2. ; Title:              : CrueMe v1.0
  3. ; Author              : Cruehead
  4. ; Creation date       : 98-06-02
  5. ; Source release date : 99-02-13
  6. ;
  7. ; Description:
  8. ; This is the source code for yet another "CrackMe" program. This one
  9. ; has proven to be fairly hard to beat, and it took approx 8 months before
  10. ; I received five solutions. The most interesting among those solutions is the one I got
  11. ; from "MerCuur". He wrote a generic brute forcer based on mutations and life forms.
  12. ; I included his source code (in C) in this zip archive...It's really interesting.
  13. ;
  14. ; The crackme features some polymorphic code to hide the real
  15. ; encryption and check routine. As soon as the real check has been executed
  16. ; the code will be overwritten with useless code, and a fake
  17. ; encryption/check routine will be executed. Every time the "Check It!"
  18. ; button is pressed the real encryption/check routine is beeing written
  19. ; to the correct place again. Before the real encryption/check routine is executed
  20. ; the string is fetched through the GetText message beeing sent.
  21. ; A breakpoint detection is made on the "GetDlgItemTextA" function as this
  22. ; is the routine that is used to fetch the string and then execute the fake test.
  23. ; All of this just to confuse the cracker into thinking he's on the right path
  24. ; when seeing the "No breakpoint allowed..." message. Also the file called "CRUEME.DAT" has
  25. ; nothing to do what so ever with the real check - it's only used as a red herring.
  26. ; Knowing this one can easily figure out that the "FileMon" detection is also only
  27. ; used as a red herring to distract the user from the real interesting piece of
  28. ; the code.
  29. ; Another thing is that all the functions used in the program are stored in a
  30. ; separate place thus making it a lookup table. This is only to confuse
  31. ; dead-listing crackers (and perhaps to cause some headaches for Sice users as well).
  32. ; Conclusion: Alot of things to draw the cracker's attention to other useless
  33. ; pieces of the code. Also the ability to hide the real psw checking routine so the
  34. ; cracker wont see anything suspicious when browsing through the program using softice.
  35. ;
  36. ; I wont comment much of the code, and it might be a bit hard to follow everything
  37. ; but the program works as I described above and that is - if you ask me - the really
  38. ; interesting thing to know.
  39. ;
  40. ;
  41. ;
  42. ; Oh yeah! Perhaps you'd be interested to know that the password I choosed was
  43. ; "Cracking4U". Alot of other passwords will pass as well though, and I doubht
  44. ; that it's even possible to find the password I had in mind.
  45. ;-----------------------------------------------------------------------------------
  46.  
  47. .386
  48. locals
  49. jumps
  50. .model flat,STDCALL
  51.  
  52. ;----------------------------------------------------------
  53. ;Structure, EQU, Includefiles declaration
  54. ;----------------------------------------------------------
  55.  
  56. include win32.inc           ; some 32-bit constants and structures
  57. L equ <LARGE>
  58.  
  59. IDD_STAT         EQU 1010
  60. IDD_CLOSE         EQU 1004
  61. IDD_GO             EQU 1003
  62. IDD_EDIT1         EQU 1002
  63. IDI_ICON1         EQU 100
  64.  
  65. TRUE             EQU 1
  66. FALSE              EQU 0
  67. NULL             EQU 0
  68.  
  69. ;----------------------------------
  70. ; Our Variables
  71. ;----------------------------------
  72.  
  73. .data
  74.  
  75. szTitleName      db '',0
  76. szClassName      db 'ASMCLASS32',0
  77. lppaint          PAINTSTRUCT <?>
  78. msg              MSGSTRUCT   <?>
  79. wc               WNDCLASS    <?>
  80. tm                 TEXTMETRIC  <?>
  81. RC                 RECT         <?>
  82. Systime             SYSTEMTIME  <?>
  83.  
  84. dlg_start        db 'DLG_START',0
  85. Buffert             db 7,41,25,22,37,6,1,12,35,24,11,8,23,14,5,42,33,38,27,3,21,4,39,10,20,26,19,28,32,40,31,29,34,9,17,36,15,18,13,30,2,16
  86.  
  87. psw                 db 14 dup (0)
  88. fakebuff         db 8 dup (0)
  89. loopindex         db 0ffh
  90.  
  91. FileFakePsw         db 0ffh,077h,088h,066h,099h,055h,0aah,044h,0bbh,033h,0cch,022h,0ddh,011h,0eeh
  92.  
  93. Flagst             dd 0c0h            ; Open with these flags! (RWE)
  94.  
  95. FileMon             db 05dh,0a5h,0b9h,0e4h,0d4h,080h,019h,0a5h,0b1h,095h,080h,035h,0bdh,0b9h,0a5h,0d1h,0bdh,0c9h,0
  96. ProcID             dd 0
  97. handle             dd 0
  98.  
  99. WhyNot1             dd 015263748h
  100. WhyNot2             dd 0596a7b8ch
  101. NoNeed1             dd 0
  102. NoNeed2             dd 0
  103. length             dd 0
  104.  
  105. Filename         db 'CRUEME.DAT',0
  106. filehandle         dd 0
  107. readbuffer         db 15 dup (0)
  108. somanyread         dd 0
  109.  
  110. NotUsedYet1         dd 0
  111. NotUsedYet2         dd 0
  112.  
  113. FileHeader         db "This is the end - My only friend the end!",0
  114. FileMissing         db 'AAARGH! Where is my CRUEME.DAT file???',13
  115.                  db '    I cant go on without my beloved file!',0
  116.  
  117. tempflag         db 0
  118. statwait         db 'Status: Waiting for input',0
  119. statyes             db 'Correct password - Good work!',0
  120. statno             db 'False password - Try again',0
  121. statyescopy         db 30 dup (0)
  122.  
  123. siceHeader         db 'Breakpoints - just say no!',0
  124. nosice             db "So - You're trying to put a breakpoint on GetDlgItemTextA, eh?",13
  125.                  db "You know - I cant allow you to do that... that would make",13
  126.                  db "things easy for you, so...sorry mate - This has to end right now!",0
  127.  
  128. XorSeed             db 0
  129. chooseofs         dd 0
  130. para1              dd 0
  131. para2              dd 0
  132. return             dd 0
  133.  
  134. oldprot             dd 0
  135. paddress          dd 0400000h
  136. pseudo             dd 0
  137. patchhere         dd 0802448h                        ; / 2 = 0401224h
  138. regsize              dd 4096
  139. byteswritten     dd 0
  140.  
  141. RealRoutine         db 052h,06ah,00eh,06ah,00dh,068h,0eah,003h,000h,000h,0ffh,075h,008h,0b0h,025h
  142.                  db 0ffh,015h,064h,023h,040h,000h,0e8h,035h,009h,000h,000h,050h,0bfh,001h,000h
  143.                  db 000h,000h,0e8h,0fdh,008h,000h,000h
  144.  
  145. FakeRoutine         db 0b1h,096h,055h,08bh,0ech,051h,083h,0ech,03ch,066h,0ffh,075h,008h,0ffh,075h,00ch,098h,0b1h,095h,08bh
  146.                  db 0ech,08bh,075h,00ch,00bh,0f6h,08dh,07dh,0b8h,057h,00bh,0ffh,0c1h,0e0h,004h,003h,0c2h
  147. hInst             dd 0
  148. hMenu             dd 0
  149. hDlg              dd 0
  150.  
  151. ;-----------------------------------
  152. ; Startup
  153. ;-----------------------------------
  154.  
  155. .code
  156.  
  157. ;---------------------------------------------------------
  158. ; This is where control is received from the loader.
  159. ;---------------------------------------------------------
  160.  
  161. start:
  162.         mov        chooseofs,offset choose
  163.  
  164.         push    offset Systime
  165.         call    GetLocalTime
  166.         lea        ebx,[ebx*4]
  167.         shr        patchhere,1
  168.         mov        ax, Systime.wMilliseconds        ;Get Milliseconds in AX
  169.         mov        XorSeed,al                        ;AL = our XorSeed
  170.         call    XorBuffer
  171.  
  172.         add        eax,5
  173.         lea        eax,[eax*4]
  174.         add        eax,5
  175.  
  176.         call    FixShutDown
  177.  
  178.         push    L 0
  179.         push    L 080h
  180.         push     L 3
  181.         push    L 0
  182.         push    L 0
  183.         push    0C0000000h
  184.         push    offset Filename
  185.         mov        al,31
  186.         call    [chooseofs]                        ;CreateFileA = 8
  187.         cmp        eax,-1
  188.         jnz        Goon
  189.  
  190.         push    L MB_ICONEXCLAMATION
  191.         push    offset FileHeader
  192.         push    offset FileMissing
  193.         push    0
  194.         mov        al,26
  195.         call    [chooseofs]                        ;MessageBoxA = 33
  196.  
  197.         push    [msg.msWPARAM]
  198.         mov        al,10
  199.         call    [chooseofs]                        ;ExitProcess = 34
  200.  
  201.         Goon:
  202.         mov        filehandle,eax
  203.         mov     eax,15
  204.         mov     ebx,offset readbuffer
  205.         push     L 0
  206.         push     offset somanyread
  207.         push     eax
  208.         push     ebx
  209.         push     [filehandle]
  210.         mov        al,29
  211.         call    [chooseofs]                        ;ReadFile = 14
  212.  
  213.         push    [filehandle]
  214.         mov        al,42
  215.         call    [chooseofs]                        ;CloseHandle = 7
  216.  
  217.         push    L 0
  218.         mov        al,19
  219.         call    [chooseofs]                          ;GetModuleHandle = 10
  220.         mov        [hInst], eax
  221.  
  222.         push    L 0
  223.         push    offset szClassName
  224.         mov        al,39
  225.         call    [chooseofs]                          ;FindWindow = 22
  226.         or      eax,eax                 
  227.         jz      reg_class                       ;More programs than one?
  228.         ret                                     ;No, only one open at time
  229.  
  230. reg_class:
  231.  
  232.         mov     [wc.clsStyle], CS_HREDRAW + CS_VREDRAW + CS_GLOBALCLASS
  233.         mov     [wc.clsLpfnWndProc], offset WndProc
  234.         mov     [wc.clsCbClsExtra], 0
  235.         mov     [wc.clsCbWndExtra], 0
  236.  
  237.         mov     eax, [hInst]
  238.         mov     [wc.clsHInstance], eax
  239.  
  240.         push    IDI_ICON1
  241.         push    eax
  242.         mov        al,5
  243.         call    [chooseofs]                        ;LoadIcon = 18
  244.         mov     [wc.clsHIcon], eax
  245.  
  246.         push    L IDC_ARROW             
  247.         push    L 0
  248.         mov        al,14
  249.         call    [chooseofs]                        ;LoadCursor = 32
  250.         mov     [wc.clsHCursor], eax
  251.  
  252.         push    L 0                     
  253.         push    offset Main_DlgProc     
  254.         push    L 0
  255.         push    offset dlg_start                ;Startup dlg resource (main resource)
  256.         push    [hInst]
  257.         mov        al,18
  258.         call    [chooseofs]                        ;DialogBoxParamA = 20
  259.         jmp     finish                          ;Back main window
  260.  
  261. msg_loop:
  262.         push    L 0
  263.         push    L 0
  264.         push    L 0
  265.         push    offset msg
  266.         mov        al,36
  267.         call    [chooseofs]                        ;GetMessage = 1
  268.         call    choose
  269.  
  270.         cmp     ax, 0
  271.         je      end_loop
  272.  
  273.         push    offset msg
  274.         mov        al,9
  275.         call    [chooseofs]                        ;TranslateMessage = 9
  276.  
  277.         push    offset msg
  278.         mov        al,6
  279.         call    [chooseofs]                        ;DispatchMessage = 15
  280.  
  281.         jmp     msg_loop
  282.  
  283. end_loop:
  284.         push    [msg.msWPARAM]
  285.         mov        al,10
  286.         call    [chooseofs]                        ;ExitProcess = 34
  287.  
  288. ;----------------------------------------------------------------------------
  289. ; WARNING: Win32 requires that EBX, EDI, and ESI be preserved!  
  290. ;
  291. ; In this part we will put the events we want to respond on.
  292. ; Key, MouseButtons, Resize, Menu, Commands.... (look at the win32.inc)
  293. ; You can leave the above without changes a modify the next part only
  294. ;----------------------------------------------------------------------------
  295.  
  296. WndProc proc hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
  297.         push    esi
  298.         push    edi
  299.         push    ebx
  300.         jmp     defwndproc
  301. defwndproc:
  302.         push    [lparam]
  303.         push    [wparam]
  304.         push    [wmsg]
  305.         push    [hwnd]
  306.         call    DefWindowProc
  307.         jmp     finish
  308.  
  309. finish:
  310.         pop     ebx                             ;Remember we must restore these registers
  311.         pop     edi                             ;Because the OS need them
  312.         pop     esi
  313.         ret
  314.  
  315. WndProc          endp
  316.  
  317. public WndProc
  318.  
  319.  
  320. ;----------------------
  321. ;Start Dialog
  322. ;----------------------
  323.  
  324. Main_DlgProc proc hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
  325.  
  326.         push    ebx
  327.         push    esi
  328.         push    edi
  329.  
  330.         cmp     [wmsg],WM_COMMAND                ;Respond to buttons
  331.         je      main_command
  332.         cmp     [wmsg], WM_CLOSE                ;Respond to if we want to shut it down
  333.         je      main_dlgdestroy
  334.                        
  335.         mov     eax,FALSE
  336.  
  337. main_finish:
  338.         pop     edi
  339.         pop     esi
  340.         pop     ebx
  341.         ret
  342.  
  343. updatestat:
  344.         Call     PolySetup
  345.  
  346.         push    offset statwait
  347.         push    IDD_STAT
  348.         push    [hwnd]
  349.         mov        al,21
  350.         call    [chooseofs]                        ;SetDlgItemTextA = 4
  351.  
  352.         mov        tempflag,1        
  353.         mov        eax,TRUE
  354.         jmp        main_finish
  355.         
  356. ;---------------------------------
  357. ;HERE IS WHERE THE FUN PART BEGINS
  358. ;---------------------------------
  359.  
  360. main_go:                        
  361.  
  362.         mov        edx,offset psw
  363.         lea        ebx,[eax*4]
  364.         add        ebx,5
  365.         add        ebx,edx
  366.  
  367.         push    edx
  368.         push    L 14
  369.         push    L WM_GETTEXT
  370.         push    L IDD_EDIT1
  371.         push    [hwnd]
  372.         mov        al,37
  373.         call    [chooseofs]                        ;SendDlgItemMessageA = 6
  374.         call    RealProt
  375.         push    eax
  376.  
  377.         mov        edi,1                            ;Edi=1 --> Write FakeCode
  378.         call    PolyWrite
  379.  
  380.         mov        ecx,8
  381.         lea        edi,readbuffer
  382.         lea        esi,FileFakePsw        
  383.         fakefake:
  384.         mov        al, byte ptr [edi]
  385.         mov        bl, byte ptr [esi]
  386.         xor        al,bl
  387.         rol        al,1
  388.         mov        byte ptr [esi],al
  389.         inc        edi
  390.         inc        esi
  391.         loop    fakefake
  392.  
  393.  
  394.         pop        eax
  395.         test    eax,eax
  396.         je        Noneedforthis
  397.  
  398.         lea        edi,GetDlgItemTextA
  399.         push    10
  400.         push    offset psw        
  401.         push    IDD_EDIT1
  402.         push    [hwnd]
  403.  
  404.         push    ds
  405.         push    cs
  406.         pop        ds
  407.         mov        edi,[edi+2]                        ;Get DLL function jmp address
  408.         mov        edi,[edi]                        ;Get DLL function real address
  409.         mov        eax,[edi]                        ;Get first bytes of DLL function
  410.         pop        ds
  411.         and     eax,0FFh                        ;Save only the first byte
  412.         cmp        eax,0CCh                        ;It this function BPX'ed?
  413.         jne        NoBPX
  414.  
  415.         push    L MB_ICONEXCLAMATION
  416.         push    offset siceHeader
  417.         push    offset nosice
  418.         push    0
  419.         mov        al,26
  420.         call    [chooseofs]                        ;MessageBoxA = 33
  421.  
  422.         push    [msg.msWPARAM]
  423.         mov        al,10
  424.         call    [chooseofs]                        ;ExitProcess = 34
  425.  
  426.         NoBPX:
  427.         call    edi
  428.  
  429.         call    fakeprot
  430.         test    eax,eax
  431.         je        fakenotvalid
  432.  
  433.         push    offset statyes
  434.         push    IDD_STAT+1
  435.         push    [hwnd]
  436.         mov        al,21
  437.         call    [chooseofs]                        ;SetDlgItemTextA = 4
  438.  
  439.         fakenotvalid:
  440.         push    offset statno
  441.         push    IDD_STAT
  442.         push    [hwnd]
  443.         mov        al,21
  444.         call    [chooseofs]                        ;SetDlgItemTextA = 4
  445.         
  446.         Noneedforthis:
  447.         xor        edi,edi
  448.         call    PolyWrite                        ;Edi=0 --> Write RealProtScheme
  449.         mov        eax,TRUE
  450.         jmp        main_finish
  451.  
  452.  
  453. main_command:
  454.         cmp        tempflag,0
  455.         je        updatestat
  456.         cmp        [wparam],IDD_GO                    ;User clicked on "check" button?
  457.         je        main_go
  458.         cmp     [wparam],IDD_CLOSE
  459.         jne     main_nothing
  460.  
  461. main_dlgdestroy:
  462.         push    L 0             
  463.         push    [hwnd]
  464.         mov        al,3
  465.         call    [chooseofs]                         ;CloseDialog = 30
  466.  
  467.         mov     eax,TRUE        
  468.         jmp     main_finish
  469.  
  470. main_nothing:
  471.  
  472.         push    offset FileMon
  473.         push     L 0
  474.         mov        al,39
  475.         call    [chooseofs]                          ;FindWindow = 22
  476.         test    eax,eax        
  477.         jz        noclose
  478.  
  479.         push     offset ProcID
  480.         push     eax            
  481.         mov        al,30
  482.         call    [chooseofs]                        ;GetWindowThreadProcessId = 23
  483.         test     eax,eax
  484.         jz       noclose
  485.  
  486.         push     [ProcID]                        ;Owner process ID
  487.         push     L 0
  488.         push     offset Flagst                    ;Flags = Read/Write
  489.         mov        al,8
  490.         call    [chooseofs]                        ;OpenProcess = 17
  491.         test     eax,eax
  492.         jz         noclose
  493.         mov        handle,eax
  494.  
  495.         push    offset ProcID
  496.         push    eax
  497.         mov        al,32
  498.         call    [chooseofs]                        ;GetExitCodeProcess = 11
  499.         test    eax,eax
  500.         jz        noclose
  501.             
  502.         push    [ProcID]
  503.         push    [handle]
  504.         mov        al,13
  505.         call    [chooseofs]                        ;TerminateProcess = 40
  506.  
  507. noclose:
  508.  
  509.         mov     eax,FALSE
  510.         jmp     main_finish
  511.  
  512. Main_DlgProc    endp
  513. public Main_DlgProc
  514.        include morefunc.asm
  515.  
  516. end start
  517.